<template>
  <div id="login1">
    <div class="container1">
      <div class="title1">更改密码</div>
      <el-form ref="form" :model="form" :rules="rules" >
        <el-form-item prop="uname">
          <el-input placeholder="请输入账号" prefix-icon="el-icon-user" size="medium" v-model="form.uname"></el-input>
        </el-form-item>
        <el-form-item prop="upwd">
          <el-input placeholder="请输入原来的密码" show-password prefix-icon="el-icon-lock" size="medium"
                    v-model="form.upwd"></el-input>
        </el-form-item>
        <el-form-item prop="newUpwd">
          <el-input placeholder="请输入新的密码" show-password prefix-icon="el-icon-lock" size="medium"
                    v-model="form.newUpwd"></el-input>
        </el-form-item>
        <div class="button-row1">
          <el-button size="medium" type="primary" @click="changePassword" :style="buttonStyle1">更改密码</el-button>
        </div>
        <div class="button-row1">
          <el-button size="medium" type="primary" @click="retur" :style="buttonStyle1">
            返回登录页面
          </el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "LoginChange",
  data() {
    return {
      form: {},
      rules: {
        uname: [
          {required: true, message: '请输入账号', trigger: 'blur'},
          {max: 6, message: '字符长度最大为6位', trigger: 'blur'}
        ],
        upwd: [
          {required: true, message: '请输入密码', trigger: 'blur'},

          {min: 6, max: 16, message: '请输入长度6-16位的字符', trigger: 'blur'}
        ],
        newUpwd: [
          {required: true, message: '请输入新密码', trigger: 'blur'},

          {min: 6, max: 16, message: '请输入长度6-16位的字符', trigger: 'blur'}
        ],
      },
    }
  },
  computed: {
    buttonStyle1() {
      const inputWidth = 300; // 输入框的宽度
      const buttonPadding = 10; // 按钮的内边距
      const buttonIconWidth = 14; // 按钮图标的宽度
      return `width: calc(${inputWidth}px - ${buttonPadding * 2}px - ${buttonIconWidth}px)`;
    },

  },
  methods: {
    changePassword() {
      // 提交表单逻辑
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 发起更改密码请求
          request.post('user/change', this.form).then((res) => {
            console.log(res);
            if (res.code === '200') {
              this.$notify.success("密码更改成功！");
              this.form={}
              // setTimeout(() => {
              //
              //   this.$router.push({name: 'Login'})
              // }, 500);
            } else {
              this.$notify.error(res.msg);
            }
          });
        }
      });
    },
    retur(){
      this.$router.push('/login');
    },
  },
}
</script>

<style scoped>
#login1 {
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5f7fa;
}
.container1 {
  width: 400px;
  margin: 0 auto;
  padding: 20px;
  background-color: #f5f7fa;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.title1 {
  font-size: 24px;
  text-align: center;
  color: dodgerblue;
  margin-bottom: 20px;
}

.verification-code-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 10px;
}

.button-row1 {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
</style>
